<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:ZoomRectApp="clr-namespace:ZoomRectApp">

   <Storyboard x:Key="RoiRectangleStoryboard">
      <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="00:00:00" Storyboard.TargetName="PART_RoiRect" Storyboard.TargetProperty="(Shape.StrokeDashOffset)">
         <SplineDoubleKeyFrame KeyTime="00:00:01" Value="10"/>
      </DoubleAnimationUsingKeyFrames>
   </Storyboard>

   <Style x:Key="RoiCornerRectangle" TargetType="{x:Type Rectangle}">
      <Setter Property="Height" Value="8"/>
      <Setter Property="Width" Value="8"/>
      <Setter Property="Fill" Value="Black"/>
      <Setter Property="Stroke" Value="White"/>
   </Style>

   <Style TargetType="{x:Type ZoomRectApp:RegionOfInterest}">
      <Setter Property="HorizontalContentAlignment" Value="Center"/>
      <Setter Property="VerticalContentAlignment" Value="Center"/>
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type ZoomRectApp:RegionOfInterest}">
               <ControlTemplate.Triggers>
                  <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                     <BeginStoryboard Storyboard="{StaticResource RoiRectangleStoryboard}"/>
                  </EventTrigger>
               </ControlTemplate.Triggers>
               <Grid
                  Margin="{TemplateBinding Margin}" 
                  Background="{TemplateBinding Background}">
                  <ContentPresenter 
                     x:Name="PART_Content" 
                     HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                     Margin="{TemplateBinding Padding}" 
                     VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                     SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                     RecognizesAccessKey="True"
                     />
                  <Canvas 
                     IsHitTestVisible="True" 
                     Background="#20000000" 
                     Visibility="{TemplateBinding RoiVisibility}"
                     >
                     <Grid
                        Canvas.Left="{TemplateBinding RoiLeft}" 
                        Canvas.Top="{TemplateBinding RoiTop}" 
                        Width="{TemplateBinding RoiWidth}"  
                        Height="{TemplateBinding RoiHeight}"  
                     >
                        <Rectangle x:Name="PART_ShaderTarget">
                           <Rectangle.Fill>
                              <VisualBrush 
                                 x:Name="PART_ContentBrush"
                                 AutoLayoutContent="False"
                                 ViewboxUnits="Absolute"
                                 Visual="{Binding ElementName=PART_Content,Mode=OneWay}" 
                                 Stretch="None" />
                           </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle 
                           x:Name="PART_RoiRect"
                           Stroke="#C0000000" 
                           StrokeDashArray="1 4 0" 
                        />
                     </Grid>
                     <Grid
                           Canvas.Left="{TemplateBinding RoiLeft}" 
                           Canvas.Top="{TemplateBinding RoiBottom}"
                           Width="{TemplateBinding RoiWidth }"
                        >
                        <StackPanel HorizontalAlignment="Right" Margin="0,2,8,0" Orientation="Horizontal">
                           <ComboBox Padding="6,0,6,0" Margin="4,0,2,0" MinWidth="40" Height="16" SelectedItem="{Binding Path=CurrentShader,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" ItemsSource="{TemplateBinding Shaders}">
                              <ComboBox.ItemTemplate>
                                 <DataTemplate>
                                    <TextBlock Text="{Binding Name }"/>
                                 </DataTemplate>
                              </ComboBox.ItemTemplate>
                           </ComboBox>
                           <Button Content="_Grow" Margin="2,0,2,0" Padding="4,-2,4,0" VerticalAlignment="Center" Height="16" Command="ZoomRectApp:RegionOfInterest.GrowRoiCommand"/>
                           <Button Content="_Shrink" Margin="2,0,2,0" Padding="4,-2,4,0" VerticalAlignment="Center" Height="16" Command="ZoomRectApp:RegionOfInterest.ShrinkRoiCommand"/>
                        </StackPanel>
                        <StackPanel HorizontalAlignment="Left" Margin="8,0,0,0" Orientation="Horizontal">
                           <Button Content="_+" Padding="0,-5,0,0" VerticalAlignment="Center" Width="16" Height="12" Command="ZoomRectApp:RegionOfInterest.ZoomInCommand"/>
                           <Button Content="_-" Padding="0,-5,0,0" VerticalAlignment="Center" Width="16" Height="12" Command="ZoomRectApp:RegionOfInterest.ZoomOutCommand"/>
                           <TextBlock x:Name="PART_RoiText"  Margin="4,0,0,0" VerticalAlignment="Center" SnapsToDevicePixels="True" Text="1.00x" >
                              <TextBlock.BitmapEffect>
                                 <OuterGlowBitmapEffect GlowColor="White" GlowSize="4">
                                    
                                 </OuterGlowBitmapEffect>
                              </TextBlock.BitmapEffect>
                           </TextBlock>
                        </StackPanel>
                     </Grid>


                     <Rectangle 
                        Style="{StaticResource RoiCornerRectangle}">
                        <i:Interaction.Behaviors>
                           <ZoomRectApp:MouseDragBehavior 
                              X="{Binding Path=RoiX0,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              Y="{Binding Path=RoiY0,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              />
                        </i:Interaction.Behaviors>
                     </Rectangle>

                     <Rectangle 
                        Style="{StaticResource RoiCornerRectangle}">
                        <i:Interaction.Behaviors>
                           <ZoomRectApp:MouseDragBehavior 
                              X="{Binding Path=RoiX1,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              Y="{Binding Path=RoiY0,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              />
                        </i:Interaction.Behaviors>
                     </Rectangle>

                     <Rectangle 
                        Style="{StaticResource RoiCornerRectangle}">
                        <i:Interaction.Behaviors>
                           <ZoomRectApp:MouseDragBehavior 
                              X="{Binding Path=RoiX0,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              Y="{Binding Path=RoiY1,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              />
                        </i:Interaction.Behaviors>
                     </Rectangle>

                     <Rectangle 
                        Style="{StaticResource RoiCornerRectangle}">
                        <i:Interaction.Behaviors>
                           <ZoomRectApp:MouseDragBehavior 
                              X="{Binding Path=RoiX1,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              Y="{Binding Path=RoiY1,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              />
                        </i:Interaction.Behaviors>
                     </Rectangle>

                     <Ellipse 
                        Width="32"
                        Height="32"
                        Stroke="#20FFFFFF"
                        StrokeThickness="2"
                        Fill="#20000000"
                        >
                        <i:Interaction.Behaviors>
                           <ZoomRectApp:MouseDragBehavior 
                              X="{Binding Path=RoiCenterX,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              Y="{Binding Path=RoiCenterY,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                              />
                        </i:Interaction.Behaviors>
                     </Ellipse>
                  </Canvas>
               </Grid>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>
</ResourceDictionary>
